package leetcode.weekly.week316;

//Solution2Test
public class Solution2 {

	public int subarrayGCD(int[] nums, int k) {
		int ans = 0;
		for (int i = 0; i < nums.length; i++) {
			int cur = nums[i];
			for (int j = i; j >= 0; j--) {
				cur = this.gcd(cur, nums[j]);
				if (cur == k) {
					ans++;
				}
			}
		}
		return ans;
	}

	public int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

}
